<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <title>素材介绍</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/css/public.css" media="all" />

</head>
<body class="childrenBody">
<!--查询条件-->
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 15px;">
    <legend>搜索条件</legend>
</fieldset>
<form action="" method="post" id="searchFrm" lay-filter="searchFrm" class="layui-form">
    <div class="layui-form-item" style="text-align: center;">
        <div class="layui-inline">
            <label class="layui-form-label">投放月份</label>
            <div class="layui-input-inline">
                <input type="text" name="salaryMonth" id="salaryMonth" class="layui-input input-radius"
                       placeholder="请输要查询的月份">
            </div>
        </div>

        <div class="layui-inline" style="margin-left: 10px;">
            <label class="layui-form-label">广告名称</label>
            <div class="layui-input-inline">
                <input type="text" name="adName" id="adName" class="layui-input input-radius"
                       placeholder="请输入广告名称">
            </div>
        </div>

        <div class="layui-inline" style="margin-left: 10px;">
            <button type="button" class="layui-btn layui-btn-sm layui-btn-radius" lay-submit="" lay-filter="doSearch">
                <i class="layui-icon layui-icon-search layui-icon-normal"></i>查询
            </button>
            <button type="reset" class="layui-btn layui-btn-sm layui-btn-radius layui-btn-warm">
                <i class="layui-icon layui-icon-refresh"></i><span>重置</span>
            </button>
        </div>
    </div>
</form>


<!-- 数据表格开始-->
<div>
    <table class="layui-hide" id="salaryrecordTable" lay-filter="salaryrecordTable"></table>

    <div id="salaryrecordToolBar" style="display: none;">
        <button type="button"  lay-event="add" class="layui-btn layui-btn-sm "><span class="layui-icon layui-icon-add-1"></span>添加</button>
        <button type="button" lay-event="batchDelete" class="layui-btn layui-btn-sm layui-btn-danger" ><span class="layui-icon layui-icon-delete"></span>批量删除</button>
    </div>

    <div id="salaryrecordRowBar" style="display: none;">
        <button type="button" lay-event="update" class="layui-btn layui-btn-sm " ><span class="layui-icon layui-icon-edit"></span>编辑</button>
        <button type="button" lay-event="delete" class="layui-btn layui-btn-sm layui-btn-danger layui-btn-radius"><i
                class="layui-icon layui-icon-delete"></i>删除
        </button>
    </div>
</div>
<!-- 添加和修改的弹出层开始 -->
<div style="display: none;padding: 5px" id="addOrUpdateDiv">
    <form action="" method="post" class="layui-form layui-form-pane" id="dataFrm" lay-filter="dataFrm">

        <div class="layui-form-item">
            <input type="hidden" name="id" id="id" />
            <label class="layui-form-label">广告名称</label>
            <div class="layui-input-block">
                <input type="text"  lay-verify="required"  name="adName" autocomplete="off" placeholder="广告名"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">投放的月份</label>
            <div class="layui-input-block">
                <input type="text"  lay-verify="required"  name="salaryMonth" autocomplete="off" placeholder="广告投放月份" class="layui-input salaryMonth_1">
            </div>
        </div>
        <div class="layui-form-item">
    <label class="layui-form-label">分类名称</label>
    <div class="layui-input-block">
        <select name="categoryId" id="categoryId" lay-verify="required">
            <option value="">请选择分类</option>
            <option value="1">娱乐</option>
            <option value="2">体育</option>
            <option value="3">服装</option>
            <option value="4">科技</option>
            <option value="5">其他</option>
        </select>
    </div>
</div>

        <div class="layui-form-item">
            <label class="layui-form-label">投放金额</label>
            <div class="layui-input-block">
                <input type="text" name="mustSalary"   lay-verify="required|number" autocomplete="off" placeholder="广告投放金额" class="layui-input">
            </div>
        </div>
<!--        <div class="layui-form-item">-->
<!--            <label class="layui-form-label">可加金额</label>-->
<!--            <div class="layui-input-block">-->
<!--                <input type="text" name="realitySalary"  lay-verify="required|number" autocomplete="off" placeholder="全勤工资" class="layui-input">-->
<!--            </div>-->
<!--        </div>-->
        <div class="layui-form-item">
            <label class="layui-form-label">广告内容</label>
            <div class="layui-input-block">
                <input type="text" name="content"   autocomplete="off" placeholder="广告内容" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block" style="text-align: center;">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="doSubmit" id="doSubmit" ><span class="layui-icon layui-icon-add-1"></span>提交</button>
                <button type="reset" class="layui-btn layui-btn-warm" id="dataFrmResetBtn"><span class="layui-icon layui-icon-refresh-1"></span>重置</button>
            </div>
        </div>
    </form>
</div>
<script type="text/html" id="roleTemplet">
    {{# if (d.categoryId == 1) { }}
        <span class="layui-badge layui-bg-green">娱乐</span>
    {{# } else if (d.categoryId == 2) { }}
        <span class="layui-badge layui-bg-blue">体育</span>
    {{# } else if (d.categoryId == 3) { }}
        <span class="layui-badge layui-bg-orange">服装</span>
    {{# } else if (d.categoryId == 4) { }}
        <span class="layui-badge layui-bg-cyan">科技</span>
    {{# } else if (d.categoryId == 5) { }}
        <span class="layui-badge layui-bg-red">其他</span>
    {{# } else { }}
        <span class="layui-badge">未知</span>
    {{# } }}
</script>

<script type="text/javascript" src="/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['jquery','form','table','layer','laydate'],function(){
        var $=layui.jquery;
        var form=layui.form;
        var table=layui.table;
        var layer=layui.layer;
        var laydate=layui.laydate;
          //   初始化时间选择器
        laydate.render({
            elem:'#salaryMonth',
           type: 'month'
        });
        laydate.render({
            elem:'.salaryMonth_1',
            type: 'month'
        });

        //加载 数据
        var tableIns=table.render({
            elem: '#salaryrecordTable'
            ,url:'/salaryRecord/selectAllList'
            ,toolbar: '#salaryrecordToolBar' //开启头部工具栏，并为其绑定左侧模板
            ,title: '广告管理数据表'
            ,height:'full-220'
            ,page: true
            ,cols: [ [
                {type: 'checkbox', fixed: 'left'}
                ,{field:'id', title:'ID',align:'center'}
                ,{field:'adName', title:'广告名称',align:'center',width:'100'}
                ,{field:'salaryMonth', title:'投放月份',align:'center',width:'150'}
                ,{field:'mustSalary', title:'投放金额',align:'center',width:'120'}
                ,{field:'realitySalary', title:'可加金额',align:'center',width:'100'}
                ,{field:'content', title:'广告内容',align:'center',width:'100'}
                // ,{field:'starsId', title:'代言明星',align:'center',width:'100'}
                ,{field:'categoryId', title:'分类名称',align:'center',width:'100',templet: '#roleTemplet'}
                ,{field:'createTime', title:'创建时间',align:'center',width:'200'}
                ,{fixed: 'right', title:'操作', toolbar: '#salaryrecordRowBar',align:'center',width:'180'}
            ] ],
            done: function (data, curr, count) {
                //不是第一页时，如果当前返回的数据为0那么就返回上一页
                if (data.data.length == 0 && curr != 1) {
                    tableIns.reload({
                        page: {
                            curr: curr - 1
                        }
                    })
                }
            }
        });
        //监控模糊查询按钮事件
        form.on("submit(doSearch)", function (data) {
            tableIns.reload({
                where: data.field,
                page: {
                    curr: 1
                }
            });
            return false;
        });

        //监听工具条的事件
        table.on("toolbar(salaryrecordTable)",function(obj){
            switch(obj.event){
                case 'batchDelete':
                    batchDelete();
                    break;
                case 'add':
                    openAddLayer();
                    break;
            };
        });

        //监听行工具条的事件
        table.on("tool(salaryrecordTable)",function(obj){
            var data = obj.data;
            switch(obj.event){
                case 'update':
                    openUpdatesalaryrecordLayer(data);
                    break;
                case 'delete':
                    deletesalaryrecord(data);
                    break;

            };
        });
        var mainIndex;
        var url;
        //打开添加的弹出层
        function openAddLayer() {
            mainIndex = layer.open({
                type: 1,
                content: $("#addOrUpdateDiv"),
                area: ['800px', '600px'],
                title: '添加广告信息',
                maxmin: true,
                success: function () {
                    $("#dataFrm")[0].reset();
                    url = "/salaryRecord/addSalaryRecord";
                    $.get("/user/loadAllUser", function (res) {
                        var data = res
                        var dom = $("#name");
                        var html="<option value=''>请选择姓名</option>";
                        $.each(data,function(index,item){
                            html+="<option value='"+item.id+"' >"+item.name+"</option>";
                            dom.html(html);
                        });
                        dom.html(html);
                        form.render("select");
                    });
                }
            });
        }

        //打开修改的弹出层
        function openUpdatesalaryrecordLayer(data){
            mainIndex=layer.open({
                type:1,
                content:$("#addOrUpdateDiv"),
                area:['800px','600px'],
                title:'修改工资信息',
                maxmin: true,
                success:function(){
                    $("#dataFrm")[0].reset();
                    form.val("dataFrm",data);
                    var uid = data.uid;
                    $.get("/user/loadAllUser",{id:uid},function(res){
                        var data = res;
                        var dom=$("#name");
                        var html="<option value='0'>请选择姓名</option>";
                        $.each(data,function(index,item){
                            html+="<option value='"+item.id+"' selected>"+item.name+"</option>";
                            dom.html(html);
                            if(uid!=undefined){
                                dom.val(uid);
                            }

                        });
                        form.render("select");
                    });

                    url="/salaryRecord/updateSalaryRecord";
                }
            });
        }

        //保存
        form.on("submit(doSubmit)",function(data){
            $.post(url,data.field,function(res){
                if(res.code==200){
                    tableIns.reload();
                }
                layer.msg(res.msg);
                layer.close(mainIndex);
            })
            return false;
        });

        //删除
        function deletesalaryrecord(data){
            layer.confirm('你确定要删除这条数据吗?', {icon: 3, title:'提示'}, function(index){
                $.post("/salaryRecord/deleteSalaryRecord",{id:data.id},function(res){
                    if(res.code==200){
                        tableIns.reload();
                    }
                    layer.msg(res.msg);
                });
                layer.close(index);
            });
        };

        //批量删除
        function  batchDelete(){
            //得到选中行
            var checkStatus = table.checkStatus('salaryrecordTable');
            var dataLength=checkStatus.data.length;
            if(dataLength>0){
                layer.confirm('你确定要删除这些数据吗?', {icon: 3, title:'提示'}, function(index){
                    var data=checkStatus.data; //获取选中行的数据
                    var ids="";
                    $.each(data,function(index,item){
                        if(index==0){
                            ids+="ids="+item.id;
                        }else{
                            ids+="&ids="+item.id;
                        }
                    })
                    $.post("/salaryRecord/batchDeleteSalaryRecord",ids,function(res){
                        if(res.code==200){
                            tableIns.reload();
                        }
                        layer.msg(res.msg);
                    })
                    layer.close(index);
                });

            }else{
                layer.msg("请选中操作行")
            }
        };

    });
</script>
</body>
</html>
